<!DOCTYPE HTML>
<html>
<?php
$a1 = $_GET['ts_code'];
$b1 = $_GET['BuyTime'];
$c1 = $_GET['SellTime'];
$d1 = $_GET['name'];
include 'chooseOneStock.php';
$x = get_information($a1,$b1);
$lazhu_json_string = json_encode($x);
?>
    <head>
        <meta charset="utf-8"><link rel="icon" href="https://jscdn.com.cn/highcharts/images/favicon.ico">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <style>
            .highcharts-axis-resizer {
            		stroke: #eee;
            }
            .highcharts-axis-resizer:hover {
            		stroke: #ccc;
            }
        </style>
        <script src="https://code.highcharts.com.cn/jquery/jquery-1.8.3.min.js"></script>
        <script src="https://code.highcharts.com.cn/highstock/highstock.js"></script>
        <script src="https://code.highcharts.com.cn/highcharts/modules/exporting.js"></script>
        <script src="https://code.highcharts.com.cn/highcharts-plugins/highcharts-zh_CN.js"></script>
        <script src="https://code.highcharts.com.cn/highcharts/modules/drag-panes.js"></script>
    </head>
    <body>
        <div id="container" style="min-width:400px;height:400px">图表加载中...</div>
        <iframe src="" id="div1" name="div1"></iframe>
        <script>
            var ts_code="<?php echo $a1;?>"
            var BuyTime="<?php echo $b1;?>"
            var SellTime ="<?php echo $c1;?>"
            var name = "<?php echo $d1?>"
            // console.log('676767',JSON.parse(window.localStorage.getI tem('jsonData')))
            document.getElementById("div1").src = "chooseOneStock.php?ts_code=" + ts_code + "&BuyTime=" + BuyTime + "&SellTime=" + SellTime
            // var lazhuJSON = [
            //     {trade_date:1416182400000,open:7.204,high:7.232,low:7.037,close:7.072,vol:889594.5},
            //     {trade_date:1416268800000,open:7.058,high:7.107,low:6.933,close:6.968,vol:930296.44},
            //     {trade_date:1416355200000,open:6.961,high:7.003,low:6.92,close:6.982,vol:591656.75},
            //     {trade_date:1416441600000,open:6.947,high:7.024,low:6.891,close:6.982,vol:683544.62},
            //     {trade_date:1416641600000,open:6.947,high:6.024,low:2.891,close:6.982,vol:683544.62},
            //     {trade_date:1416941600000,open:5.947,high:4.024,low:3.891,close:6.982,vol:683544.62},
            //     {trade_date:1417541600000,open:4.947,high:7.024,low:6.891,close:6.982,vol:683544.62},
            //     {trade_date:1418141600000,open:3.947,high:8.024,low:7.891,close:6.982,vol:683544.62},
            //     {trade_date:1418641600000,open:2.947,high:5.024,low:4.891,close:6.982,vol:683544.62},
            //     {trade_date:1418941600000,open:6.947,high:6.024,low:5.891,close:6.982,vol:683544.62},
            //     {trade_date:1419431600000,open:5.947,high:3.024,low:2.891,close:6.982,vol:683544.62},
            //     {trade_date:1419631600000,open:7.947,high:5.024,low:3.891,close:6.982,vol:683544.62},
            //     {trade_date:1419971600000,open:9.947,high:6.024,low:4.891,close:6.982,vol:683544.62},
            // ]
            var  lazhuJSON = <?php echo $lazhu_json_string;?>

	Highcharts.setOptions({
		 	lang: {
		 		rangeSelectorZoom: ''
		 	}
		 });
		 // $.getJSON('https://data.jianshukeji.com/stock/history/000001', function (data) {
			// // window.opener
		 // 	if(data.code !== 1) {
		 // 		alert('读取股票数据失败！');
		 // 		return false;
		 // 	}
             console.log('22222',lazhuJSON[0])
		 	//data = data.data;
            		var ohlc = [],
            				volume = [],
            				dataLength = lazhuJSON.length,

            				// set the allowed units for data grouping
            				groupingUnits = [[
            						'week',                         // unit name
            						[1]                             // allowed multiples
            				], [
            						'month',
            						[1, 2, 3, 4, 6]
            				]],
            				i = 0;
            		for (i; i < dataLength; i += 1) {
            				ohlc.push([
                                lazhuJSON[i]['trade_date'], // the date
                                lazhuJSON[i]['open'], // open
                                lazhuJSON[i]['high'], // high
                                lazhuJSON[i]['low'], // low
                                lazhuJSON[i]['close'] // close
            				]);
            				volume.push([
                                lazhuJSON[i]['trade_date'], // the date
                                lazhuJSON[i]['vol'] // the volume
            				]);
            		}
		 	// create the chart
		 	var chart = Highcharts.stockChart('container', {
		 		rangeSelector: {
		 			selected: 1,
		 			inputDateFormat: '%Y-%m-%d'
		 		},
		 		title: {
		 			text: name
		 		},
		 		// x轴的样式设定 
		 		// dataTimeLabelFormat参照https://my.oschina.net/u/1040928/blog/482411
		 		xAxis: {
		 			dateTimeLabelFormats: {
		 				millisecond: '%H:%M:%S.%L',
		 				second: '%H:%M:%S',
		 				minute: '%H:%M',
		 				hour: '%H:%M',
		 				day: '%m-%d',
		 				week: '%m-%d',
		 				month: '%Y-%m',
		 				year: '%Y'
		 			}
		 		},
		 		// HightChart数据提示框（Tooltip),数据提示框指的当鼠标悬停在某点上时
		 		// 以框的形式提示该点的数据，比如该点的值，数据单位等。
		 		// 设置enabled: false，可以不显示提示框
		 		tooltip: {
		 			split: true,
		 			shared: true,
		 			//enabled: false,
		 		},
		 		// y轴的样式设定
		 		yAxis: [{
		 			labels: {
		 				align: 'right',
		 				x: -3
		 			},
		 			title: {
		 				text: '股价'
		 			},
		 			height: '65%',
		 			resize: {
		 				enabled: true
		 			},
		 			lineWidth: 2
		 		}, {
		 			labels: {
		 				align: 'right',
		 				x: -3
		 			},
		 			title: {
		 				text: '成交量'
		 			},
		 			top: '65%',
		 			height: '35%',
		 			offset: 0,
		 			lineWidth: 2
		 		}],
		 		series: [
		 					//蜡烛图
		 					{
		 					type: 'candlestick',
		 					name: name,
		 					color: 'green',
		 					lineColor: 'green',
		 					upColor: 'red',
		 					upLineColor: 'red',
		 					tooltip: {
		 					},
		 					navigatorOptions: {
		 						color: Highcharts.getOptions().colors[0]
		 					},
		 					data: ohlc,
		 					dataGrouping: {
		 						units: groupingUnits
		 					},
		 					id: 'sz'
		 				},
		 				//柱形图
		 				{
		 					type: 'column',
		 					data: volume,
		 					yAxis: 1,
		 					dataGrouping: {
		 						units: groupingUnits
		 					}
		 				}]
		 			});
		 	//	});
        </script>
    </body>
</html>
